package cn.naughtior.shch.mobile.controller;

import cn.naughtior.shch.entity.User;
import cn.naughtior.shch.exception.UserException;
import cn.naughtior.shch.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping("/list/{name}")
    public String list(@PathVariable("name") String name, Model model) {
        List<User> list = new ArrayList<>();
        try {
            list = userService.selectUserByName(name);
            model.addAttribute("users", list);
        } catch (UserException e) {
            e.printStackTrace();
        }
        return "user/user";
    }
}
